package pe.com.nextel.localizacion;

import java.util.List;

import pe.com.nextel.bean.GrupoDTO;
import pe.com.nextel.bean.TransaccionDTO;
import pe.com.nextel.bean.UsuarioDTO;
import pe.com.nextel.dao.iface.GrupoDAO;
import pe.com.nextel.util.ServicioLocalizacionConnectionUtil;
import pe.com.nextel.util.XMLUtil;

public class LocalizacionGrupoDAO implements GrupoDAO {

	@Override
	public List<GrupoDTO> listar(int idMonitor) {
		return null; //no se implementa en esta clase
	}

	@Override
	public List<GrupoDTO> listarPorCuenta(int idCuenta) {
		return null; // no se implementa en esta clase
	}

	@Override
	public int registrar(GrupoDTO grupo) {
		return 0; //No se implementa en esta clase
	}

	@Override
	public boolean modificar(GrupoDTO grupo) {
		return false; //no se implementa en esta clase
	}

	@Override
	public boolean eliminar(int idGrupo) {
		return false; //No se implementa en esta clase
	}

	@Override
	public boolean asignarGrupo(int idGrupo, List<UsuarioDTO> usuarios) {
		return false; //no se implementa en esta clase
	}

	@Override
	public GrupoDTO obtener(int idGrupo) {
		return null; //no se implementa en esta clase
	}

	@Override
	public TransaccionDTO localizar(List<UsuarioDTO> usuarios) {

//		String xmlResponse="13427405308901342740591296<?xml version=\"1.0\" ?><!DOCTYPE svc_result SYSTEM \"MLP_SVC_RESULT_300.DTD\"><svc_result ver=\"3.0.0\"><slia ver=\"3.0.0\"><pos><msid enc=\"ASC\" type=\"MIN\">51946240592</msid><pd><time utc_off=\"+0000\">20111226234232</time><shape><CircularArea srsName=\"www.epsg.org#4326\"><coord><X>12 09 36.727295S</X><Y>76 57 21.934204W</Y><Z>NaN</Z></coord><radius>4999</radius></CircularArea></shape></pd></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946240764</msid><pd><time utc_off=\"+0000\">20111227045129</time><shape><CircularArea srsName=\"www.epsg.org#4326\"><coord><X>12 00 48.120117S</X><Y>77 04 47.347412W</Y><Z>NaN</Z></coord><radius>4999</radius></CircularArea></shape></pd></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981133152</msid><pd><time utc_off=\"+0000\">20111227021917</time><shape><CircularArea srsName=\"www.epsg.org#4326\"><coord><X>12 05 18.644714S</X><Y>77 05 37.03308W</Y><Z>NaN</Z></coord><radius>46</radius></CircularArea></shape></pd></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981133199</msid><poserr><result resid=\"6\">POSITION METHOD FAILURE</result><add_info>Location server error: 163, The LFC Driver reported a position failure</add_info><time utc_off=\"+0000\">20111227050414</time></poserr></pos></slia></svc_result>";
		String xmlResponse=ServicioLocalizacionConnectionUtil.llamarAplicacionConexionLocalizacion(usuarios);
//		String xmlResponse="13553453530171355345393517<?xml version=\"1.0\" ?><!DOCTYPE svc_result SYSTEM \"MLP_SVC_RESULT_300.DTD\"><svc_result ver=\"3.0.0\"><slia ver=\"3.0.0\"><pos><msid enc=\"ASC\" type=\"MIN\">51981539346</msid><poserr><result resid=\"5\">ABSENT SUBSCRIBER</result><add_info>Received 'ABSENT SUBSCRIBER' from underlying GMLC</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946186724</msid><poserr><result resid=\"6\">POSITION METHOD FAILURE</result><add_info>Positioning Failure in HLR</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946186963</msid><poserr><result resid=\"6\">POSITION METHOD FAILURE</result><add_info>Positioning Failure in HLR</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981539248</msid><poserr><result resid=\"5\">ABSENT SUBSCRIBER</result><add_info>Received 'ABSENT SUBSCRIBER' from underlying GMLC</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946574252</msid><poserr><result resid=\"6\">POSITION METHOD FAILURE</result><add_info>Positioning Failure in HLR</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946577214</msid><poserr><result resid=\"5\">ABSENT SUBSCRIBER</result><add_info>Received 'ABSENT SUBSCRIBER' from underlying GMLC</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51947262821</msid><poserr><result resid=\"6\">POSITION METHOD FAILURE</result><add_info>Positioning Failure in HLR</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981533051</msid><poserr><result resid=\"5\">ABSENT SUBSCRIBER</result><add_info>Country Code: 51  Country Id: PE</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946187985</msid><poserr><result resid=\"6\">POSITION METHOD FAILURE</result><add_info>Positioning Failure in HLR</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946576640</msid><poserr><result resid=\"6\">POSITION METHOD FAILURE</result><add_info>Country Code: 51  Country Id: PE; Positioning Failure in MSC</add_info><time utc_off=\"+0000\">20121212204938</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981228184</msid><pd><time utc_off=\"+0000\">20121212204936</time><shape><CircularArea srsName=\"www.epsg.org#4326\"><coord><X>12 05 56.001663S</X><Y>77 01 32.010498W</Y><Z>NaN</Z></coord><radius>49</radius></CircularArea></shape><alt>204</alt><alt_acc>42</alt_acc><lev_conf>68</lev_conf></pd><gsm_net_param><neid><vmscid><vmscno>511981500005</vmscno></vmscid></neid></gsm_net_param></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946573376</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51946573376 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946573379</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51946573379 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946573596</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51946573596 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946575647</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51946575647 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946579169</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51946579169 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51946579244</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51946579244 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981520889</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51981520889 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981520898</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51981520898 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos><pos><msid enc=\"ASC\" type=\"MIN\">51981537788</msid><poserr><result resid=\"4\">UNKNOWN SUBSCRIBER</result><add_info>MobileStationID: 51981537788 Type: MIN Subscriber is not in database</add_info><time utc_off=\"+0000\">20121212204902</time></poserr></pos></slia></svc_result> ";
		if(xmlResponse.isEmpty()){
			return null;
		}
		String horaInicio = xmlResponse.substring(0,13);
		String horaFin = xmlResponse.substring(13,26);
		xmlResponse = xmlResponse.substring(26);
		TransaccionDTO transaccion = XMLUtil.readXMLLocalizationServer(xmlResponse);
		if(transaccion!=null){
			transaccion.setHoraInicio(horaInicio);
			transaccion.setHoraFin(horaFin);
		}
		
		//ERROR
//		List<PosicionDTO> posiciones = new ArrayList<PosicionDTO>();
//		posiciones = transaccion.getPosiciones();
//
//		for(int i = 0; i<usuarios.size(); i++){
//			posiciones.get(i).setUsuario(usuarios.get(i));
//		}
//
//		transaccion.setPosiciones(posiciones);
		//ERROR
		return transaccion;

		
	}

}
